﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;

namespace PulseApp
{
    public class Person
    {
        private t_person _person;


        public Person()
        { 
            _person = new t_person();
        }


        public Person(string lastName, string firstName, string sex, int age, int height, int weight, int hbp, int lbp)
        {
            _person = new t_person();
            _person.last_name = lastName;
            _person.first_name = firstName;
            _person.sex = sex;
            _person.age = age;
            _person.height = height;
            _person.weight = weight;
            _person.hbp = hbp;
            _person.lbp = lbp;
        }

        public Person(string lastName, string firstName, string sex, int age, int height, int weight, int hbp, int lbp, string street, string city, string province, string country, string postCode, string phone, string fax, string email, string username, string password, int role)
        {
            _person = new t_person();
            _person.last_name = lastName;
            _person.first_name = firstName;
            _person.sex = sex;
            _person.age = age;
            _person.height = height;
            _person.weight = weight;
            _person.hbp = hbp;
            _person.lbp = lbp;
            _person.street = street;
            _person.city = city;
            _person.province = province;
            _person.country = country;
            _person.post_code = postCode;
            _person.phone = phone;
            _person.email = email;
            _person.username = username;
            _person.password = password;
            _person.role = role;
        }

        public Person(t_person person)
        {
            _person = person;
        }


        public int Id
        {
            get { return _person.ID; }
        }

        public string LastName
        {
            get { return _person.last_name; }
            set { _person.last_name = value; }
        }

        public string FirstName
        {
            get { return _person.first_name; }
            set { _person.first_name = value; }
        }

        public string Sex
        {
            get { return _person.sex; }
            set { _person.sex = value; }
        }

        public int Age
        {
            get { return _person.age.Value; }
            set { _person.age = value; }
        }

        public int Height
        {
            get { return _person.height.Value; }
            set { _person.height = value; }
        }

        public int Weight
        {
            get { return _person.weight.Value; }
            set { _person.weight = value; }
        }

        public int Hbp
        {
            get { return _person.hbp.Value; }
            set { _person.hbp = value; }
        }

        public int Lbp
        {
            get { return _person.lbp.Value; }
            set { _person.lbp = value; }
        }

        public string City
        {
            get { return _person.city; }
            set { _person.city = value; }
        }

        public string Street
        {
            get { return _person.street; }
            set { _person.street = value; }
        }

        public string Province
        {
            get { return _person.province; }
            set { _person.province = value; }
        }

        public string Country
        {
            get { return _person.country; }
            set { _person.country = value; }
        }

        public string PostCode
        {
            get { return _person.post_code; }
            set { _person.post_code = value; }
        }

        public string Phone
        {
            get { return _person.phone; }
            set { _person.phone = value; }
        }


        public string Email
        {
            get { return _person.email; }
            set { _person.email = value; }
        }

        public string Username
        {
            get { return _person.username; }
            set { _person.username = value; }
        }

        public string Password
        {
            get { return _person.password; }
            set { _person.password = value; }
        }

        public int Role
        {
            get { return _person.role.Value; }
            set { _person.role = value; }
        }

        public t_person TPerson
        {
            get { return _person; }
            set { _person = value; }
        }

        public Person(int theID)
        {
            using (DbEntities db = new DbEntities())
            {
                var persons = from p in db.t_person
                              where p.ID == theID
                              select p;
                if (persons.Any())
                {
                    _person = persons.FirstOrDefault();
                }
            }
        }



        public string toResult()
        {
            string result = "";
            result += FirstName + " " + LastName + ": " + Age + " years old " + Sex + ", " + Height + " cms high and ";
            result += Weight + " kgs weight.\r\nThe Blood Pressure is " + Hbp + "/" + Lbp;
            return result;
        }
    }
}
